package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
@HttpInlet(Conn.COMMENT_INDEX)
public class EvaluateListGet extends BaseAsyGet<EvaluateListGet.EvaluateListEntity> {

    public String show_id, user_id;
    public int page;

    public EvaluateListGet(AsyCallBack<EvaluateListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected EvaluateListEntity parser(JSONObject object) throws Exception {

        if(object.optInt("code")==200){

            EvaluateListEntity evaluateListEntity = new EvaluateListEntity();

            evaluateListEntity.state = object.optString("state");

            JSONObject jsonObject_list = object.optJSONObject("list");

            evaluateListEntity.total = jsonObject_list.optInt("total");
            evaluateListEntity.current_page = jsonObject_list.optInt("current_page");
            evaluateListEntity.per_page = jsonObject_list.optInt("per_page");

            JSONArray jsonArray = jsonObject_list.optJSONArray("data");
            for(int i=0;i<jsonArray.length();i++){

                JSONObject jsonObject = jsonArray.optJSONObject(i);

                EvaluateEntity evaluateEntity = new EvaluateEntity();
//                evaluateEntity.id = jsonObject.optString("id");
                evaluateEntity.user_id = jsonObject.optString("user_id");
                evaluateEntity.star = jsonObject.optString("star");
                evaluateEntity.content = jsonObject.optString("content");
                evaluateEntity.zambia = jsonObject.optString("zambia");
                evaluateEntity.datetime = jsonObject.optString("datetime");
                evaluateEntity.nickname = jsonObject.optString("nickname");
                evaluateEntity.avatar = Conn.BASE_URL + jsonObject.optString("avatar");
                evaluateEntity.zambia_state = jsonObject.optString("zambia_state");
                evaluateEntity.posttime = jsonObject.optString("posttime");

                evaluateListEntity.list.add(evaluateEntity);

            }

            return evaluateListEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class EvaluateListEntity{

        public List<EvaluateEntity> list = new ArrayList<>();
        public String state;
        public int total, current_page, per_page;

    }

    public static class EvaluateEntity{

        public String user_id, star, content, zambia, datetime, nickname, avatar, zambia_state, posttime;//id,

    }

}
